package com.gxa.autoparts.portal.service.impl;

import com.alibaba.fastjson.JSON;
import com.gxa.autoparts.core.pojo.GoodsCollectionVo;
import com.gxa.autoparts.core.pojo.UserCollection;
import com.gxa.autoparts.core.util.JsonUtil;
import com.gxa.autoparts.portal.mapper.UserCollectionMapper;
import com.gxa.autoparts.portal.service.UserCollectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

@Service
public class UserCollectionServiceImpl implements UserCollectionService {

    @Autowired
    UserCollectionMapper userCollectionMapper=null;

    @Override
    public List<Map> findAll(Long id) {
        List<Map> all = userCollectionMapper.findAll();
//        List<GoodsCollectionVo> list=new ArrayList<>();
//        for (Map map : all) {
//            GoodsCollectionVo goodsCollectionVo=new GoodsCollectionVo();
//            goodsCollectionVo.setId(Long.valueOf(map.get("id").toString()));
//            goodsCollectionVo.setSkuId(Long.valueOf(map.get("skuId").toString()));
//            goodsCollectionVo.setImg(map.get("img").toString());
//            goodsCollectionVo.setRemarkPrice(Double.valueOf(map.get("markPrice").toString()));
//            goodsCollectionVo.setSalePrice(Double.valueOf(map.get("salePrice").toString()));
//            String jsonString = map.get("specs").toString();
//            StringBuffer specs=new StringBuffer(map.get("name").toString());
//            Map map1 = JsonUtil.readToObject(jsonString, Map.class);
//
//            Set set = map1.keySet();
//            for (Object o : set) {
//                specs.append(map1.get(o).toString()+" ");
//            }
//            goodsCollectionVo.setTitle(specs.toString());
//
//            list.add(goodsCollectionVo);
//        }
        return all;

    }

    @Override
    public void update(List<Long> list) {
        for (Long aLong : list) {
            userCollectionMapper.deleteByPrimaryKey(aLong);
        }
    }

    @Override
    public void add(Long userId, Long goodsId) {
        UserCollection userCollection=new UserCollection();
        userCollection.setUserId(userId);
        userCollection.setGoodsId(goodsId);
        userCollection.setCollectTime(new Date());
        userCollectionMapper.insertSelective(userCollection);
    }
}
